import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/utils/key_val_model.dart';
import 'package:search_people/value/topcolors.dart';
import '../../../../../utils/util.dart';
import '../index.dart';

class SearchHistoryView extends GetView<DynamicSearchController> {
  SearchHistoryView({
    Key? key,
    this.list,
    this.onTap,
  }) : super(key: key);
  final VoidCallback? onTap;
  final List<KeyValModel>? list;
  @override
  Widget build(BuildContext context) {
    return isZeroList(list)
        ? const SizedBox()
        : Container(
            // padding: EdgeInsets.symmetric(horizontal: gap12, vertical: gap10),
            padding: EdgeInsets.fromLTRB(12.r, 10.r, 12.r, 0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Expanded(
                      child: Text(
                        '搜索历史',
                        style: TextStyle(
                            color: const Color(0xff888888), fontSize: 13.sp),
                      ),
                    ),
                    IconButton(
                      onPressed: () {
                        controller.actionDeleteAllHistory();
                      },
                      icon: Icon(
                        IconUtil.delete,
                        color: const Color(0xffbbbbbb),
                        size: 14.r,
                      ),
                    ),
                  ],
                ),
                Wrap(
                  spacing: 10.w,
                  runSpacing: 10.w,
                  children: list!
                      .map((e) => InkWell(
                            onTap: () {
                              controller.actionHistoryTap(e.key);
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(
                                  horizontal: 12.r, vertical: 6.r),
                              height: 30.w,
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(15.r)),
                              child: Text(
                                e.key,
                                style: TextStyle(
                                    color: TopColors.black_33, fontSize: 14.sp),
                              ),
                            ),
                          ))
                      .toList(),
                ),
              ],
            ),
          );
  }
}
